#include "StdAfx.h"
#include "Matrix.h"

//Matrix::Matrix(double** mat, int dim) 
Matrix::Matrix(float** mat, int iMax,int jMax)
{
	this->intMat=NULL;
	this->mat = mat;
	this->iMax = iMax;
	this->jMax = jMax;
}
/*
Matrix::Matrix(double** listMat, int iMax,int jMax)
{
	this->listMat=listMat;
	this->mat = NULL;
	this->iMax = iMax;
	this->jMax = jMax;
}
*/
Matrix::Matrix(int** intMat, int iMax,int jMax)
{
	this->intMat=intMat;
	this->mat = NULL;
	this->iMax = iMax;
	this->jMax = jMax;
}
Matrix::~Matrix(void)
{
	if(mat!=NULL){
		for(int i=0;i<this->iMax;i++){
			delete this->mat[i];
		}
		delete this->mat;
	}


	if(intMat!=NULL){
		for(int i=0;i<this->iMax;i++){
			delete this->intMat[i];
		}
		delete this->intMat;
	}


	/*
	if(listMat!=NULL){
		int noOfItemsInList;
		for(int i=0;i<iMax;i++){
			noOfItemsInList =listMat[i]->size(); 
			for(int j=0;j<jMax;j++){
			
			
			}
			delete this->listMat[i];
		}
		delete this->listMat;
	}
	*/
}

int Matrix::getIMax(){
	return this->iMax;
}

int Matrix::getJMax(){
	return this->jMax;
}



float** Matrix::getMat(){
	return this->mat;
}

float Matrix::getVal(int i, int j){
	return this->mat[i][j];
}

void Matrix::setMat(float **mat){
	this->mat = mat;
}

void Matrix::setVal(int i, int j, float val){
	this->mat[i][j] = val;
}



/*For integer matrix*/
int Matrix::getValIntMat(int i, int j){
	return this->intMat[i][j];
}

int** Matrix::getIntMat(){
	return this->intMat;
}
void Matrix::setValIntMat(int i, int j, int val){
	this->intMat[i][j] = val;
}
void Matrix::setIntMat(int** intMat){
	this->intMat = intMat;

}

Matrix*  Matrix::getTransposeMat(){

	float** returnMat = new float*[this->jMax];
	float* returnTmpArr;

	for(int i=0;i<this->jMax;i++){
		returnTmpArr = new float[this->iMax];
		for(int j=0;j<this->iMax;j++){
			returnTmpArr[j] = this->getVal(j,i);
		}
		returnMat[i] = returnTmpArr;
	}


	/*for(int i=0;i<this->iMax;i++){
			delete this->mat[i];
	}
	delete this->mat;*/

	//delete sourceMatrix;
	return new Matrix(returnMat,this->jMax,this->iMax);




}